package com.excample.interupt;

import java.util.concurrent.TimeUnit;

/**
 * @Author: sn
 * @Desc something
 * @Date: 2021/8/30
 */
public class ThreadInterrupt2{
    static volatile boolean flag = true;
    public static void main(String[] args) {

        Thread t = new Thread(new Run4(flag));
        t.start();
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        flag = false;
        System.out.println("程序结束");

    }
}

class Run4 implements Runnable{
    volatile boolean flag;

    public Run4(boolean flag) {
        this.flag = flag;
    }

    @Override
    public void run() {
        while(flag){
            System.out.println("运行中");
        }
    }
}
